package it.hopeless.jee6.security;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.io.Serializable;

/**
 * User: frico
 * Date: Jan 31, 2010
 * Time: 2:32:23 AM
 */
@ManagedBean(name="authenticator")
@SessionScoped
public class AuthenticationController implements Serializable{
    private User user = new User();
    private static final Logger logger = LoggerFactory.getLogger(AuthenticationController.class);
    @EJB
    private AuthenticationService authentication;

    public User getUser() {
        return user;
    }

    public boolean authenticate(){
        logger.debug("Calling service for authentication");
        return authentication.authenticate(user);
    }

    public boolean isLoggedIn() {
        return user.getUsername()!=null;
    }

    public String login(){
        authenticate();
        return "";
    }

    public void logout() {
        user = new User();
    }
}
